package wowmobile;

import environment.Cave;
import environment.Environment;
import environment.Grass;
import environment.HighGrass;
import environment.Passage;
import environment.QuestGiver;
import environment.Road;
import environment.Rock;
import environment.Sand;
import environment.Tree;
import environment.QuestGiver;

public class Area
{
    private Environment[][] area;
    private String name;
    private int SizeX=100;
    private int SizeY=100;

    public String getName()
    {
        return name;
    }

    public Area(String name)
    {
        area=new Environment[SizeY][SizeX];
        this.name=name;
        makeStartArea();
    }

    public void setItemAt(String environment,int i, int j, int image)
    {
        switch(image)
        {
            case 5:
                area[i][j]=new Cave(environment);
                break;
            case 6:
                area[i][j]=new Grass(environment);
                break;
            case 7:
                area[i][j]= new HighGrass(environment);
                break;
            case 8:
                area[i][j]= new Passage();
                break;
            case 9:
                area[i][j]= new Road();
                break;
            case 10:
                area[i][j]= new Rock();
                break;
            case 11:
                area[i][j]= new Sand(environment);
                break;
            case 12:
                area[i][j]= new Tree();
                break;
            case 13:
                area[i][j] = new QuestGiver();
        }
    }

    public Environment getItemAt(int i, int j)
    {
        return area[i][j];
    }

    //tymczasowa metoda do wygenerowania jakies tam planszy
    private void makeStartArea()
    {   String[] table = new String[SizeX*SizeY];
        table=Database.ask("SELECT Map FROM Area WHERE Name='start'",SizeX*SizeY);
                for(int i=0; i<SizeY; i++){
                    for(int j=0; j<SizeX; j++){
                        String temp_helper = table[SizeY*i+j];
                        if(temp_helper.startsWith("Cave")){
                            area[i][j]=new Cave(temp_helper);
                        }else if(temp_helper.startsWith("Grass")){
                            area[i][j]=new Grass(temp_helper);
                        }else if(temp_helper.startsWith("HighGrass")){
                            area[i][j]= new HighGrass(temp_helper);
                        }else if(temp_helper.startsWith("Passage")){
                            area[i][j]= new Passage();
                        }else if(temp_helper.startsWith("Road")){
                            area[i][j]= new Road();
                        }else if(temp_helper.startsWith("Rock")){
                            area[i][j]= new Rock();
                        }else if(temp_helper.startsWith("Sand")){
                            area[i][j]= new Sand(temp_helper);
                        }else if(temp_helper.startsWith("Tree")){
                            area[i][j]= new Tree();
                        } else if(temp_helper.startsWith("Quest")){
                            Quest quest=Database.getQuest(temp_helper);
                            area[i][j]= new QuestGiver(quest);
                        }
                    }
                }
            }

    public String toString()
    {
        String tmp="";
        for(int i=0; i<SizeY; i++)
        {
            for(int j=0; j<SizeX; j++)
                if(j==SizeX)
                    tmp+=area[i][j];
                else
                    tmp=tmp+area[i][j]+",";
             if(i!=SizeY)
                 tmp+="\n";
        }
        return tmp;
    }
}
